// 一进来先读取localStorage 没有值就赋值一个空对象  有值就用现有的值
// 刷新就不会清空了
const isuser = JSON.parse(localStorage.getItem('loginuser')) || {
  userName: '',
  user_id: ''
}
export default {
  namespaced: true,
  state: isuser,
  actions: {},
  mutations: {
    // 登入
    setUser(state, data) {
      state.userName = data.userName
      state.user_id = data.user_id
      localStorage.setItem(
        'loginuser',
        JSON.stringify({
          userName: data.userName,
          user_id: data.user_id
        })
      )
    },
    LOG_Out(state) {
      state.userName = ''
      state.user_id = ''
      // 清空本地登录信息
      localStorage.removeItem('loginuser')
      localStorage.removeItem('user')
    }
  }
}
